package com.qfedu.hotelssm.controller;

import com.alibaba.excel.EasyExcel;
import com.qfedu.hotelssm.dto.CtOrdersDto;
import com.qfedu.hotelssm.entity.CtOrders;
import com.qfedu.hotelssm.service.intf.CtOrdersService;
import com.qfedu.hotelssm.vo.PageBean;
import com.qfedu.hotelssm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author dzl
 * @date 2022/8/28 22:39
 */
@RestController
@RequestMapping("/api/orders/")
public class CtOrdersController {
    @Autowired
    private CtOrdersService service;

    //新增订单
    @PostMapping("save.do")
    public R save(CtOrders orders){
        return service.save(orders);
    }
    //删除订单
    @GetMapping("del.do")
    public R del(int id){
        return service.del(id);
    }
    //使用名字对订单模糊查询的page分页查询
    @GetMapping("page.do")
    public PageBean page(String username,int page,int limit){
        return service.page(username, page, limit);
    }
    //更新订单
    @PostMapping("update.do")
    public R update(CtOrders orders){
        return service.update(orders);
    }
    //导出
    @GetMapping("download.do")
    public void download(HttpServletResponse response) throws IOException {
        //1.设置 响应消息头 下载
        response.setHeader("content-disposition","attachment;filename=orders-"+System.currentTimeMillis()+".xlsx");
        //2.查询菜单数据
        List<CtOrdersDto> list =service.all();
        //3.实现数据写出 Excel生成
        EasyExcel.write(response.getOutputStream(), CtOrdersDto.class).sheet().doWrite(list);
    }

    //导入
//    @PostMapping("upload.do")
//    public R upload(MultipartFile file) throws IOException {
//        System.out.println("成功了啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊");
//        return service.upload(file);
//   }
    //批量删除
    @PostMapping("delids.do")
    public R delids(int[] ids){
        return service.delIds(ids);
    }


}
